package com.dimaidt.girl.controller;

import com.dimaidt.girl.properties.GirlProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : Alex Hu
 * date : 2020/2/25 下午21:32
 * description :
 */
@RestController
public class HelloController {
    @Autowired
    private GirlProperties girlProperties;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String say() {
        return girlProperties.getContent();
    }

    /**
     * 参数1 @RequestParam
     * http://127.0.0.1:8082/girl/hi?cupSize=F&age=16
     * age参数默有默认值，可不传；若无默认值则报错
     * http://127.0.0.1:8082/girl/hi?cupSize=F
     */
    @GetMapping(value = "/hi")
    public String say(@RequestParam("cupSize") String cupSize,
                      @RequestParam(value = "age", required = false, defaultValue = "0") String age) {
        return cupSize + age;
    }

    /**
     * 参数2 @PathVariable
     * http://127.0.0.1:8082/girl/echo/F
     */
    @GetMapping(value = "/echo/{cupSize}")
    public String say(@PathVariable("cupSize") String cupSize) {
        return cupSize;
    }
}
